package br.com.solutions.delivery.controller;

import br.com.solutions.delivery.entity.Route;
import br.com.solutions.delivery.google.GoogleMapsController;
import br.com.solutions.delivery.intf.Travel;
import br.com.solutions.delivery.screen.TravelScreen;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class TravelScreenController {
    
    private Travel travel;
    private TravelScreen form;
    
    private static TravelScreenController instance;

    private class GerarMapaActionListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFrame frame = new JFrame();        
            frame.setSize(500, 500);
            JLabel label = new JLabel(new ImageIcon(GoogleMapsController.getMap(travel.getRoutes())));
            frame.add(label);
            frame.setVisible(true);
        }
    }
    
    private class AdicionarRotaActionListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            RouteScreenController.getInstance(travel).showScreen();
        }
    }
    private TravelScreenController(){
        this.travel = new Travel();
        this.form = TravelScreen.getInstance();     
        this.form.getBtnAdicionarRota().addActionListener(new AdicionarRotaActionListener());
        this.form.getBtnGerarMapa().addActionListener(new GerarMapaActionListener());
    }
    
    public void showScreen(){
        this.form.setVisible(true);
    }
    
    public static TravelScreenController getInstance(){
        if (instance == null){
            instance = new TravelScreenController();
        }
        return instance;
    }

}